package org.smarthings.things.management.impl;

import java.util.Collections;
import java.util.List;

import org.smarthings.things.management.Thing;
import org.smarthings.things.management.ThingProperty;
import org.smarthings.things.management.ThingPropertyCollection;

public class ThingPropertyCollectionImpl implements ThingPropertyCollection {

	private List<ThingProperty> properties;

	public ThingPropertyCollectionImpl(List<ThingProperty> properties) {
		this.properties = Collections.unmodifiableList(properties);
	}

	@Override
	public ThingProperty getPropertyByUUID(String propertyUUID) {
		for (ThingProperty property : properties) {
			if (propertyUUID.equals(property.getUUID())) {
				return property;
			}
		}
		return null;
	}

	@Override
	public ThingProperty getPropertyByType(String propertyType) {
		for (ThingProperty property : properties) {
			if (propertyType.equals(property.getType())) {
				return property;
			}
		}
		return null;
	}

	@Override
	public List<ThingProperty> listProperties() {
		return properties;
	}

	void bindThing(Thing thing) {
		for (ThingProperty property : properties) {
			ThingPropertyImpl implproperty = (ThingPropertyImpl) property;
			implproperty.bindThing(thing);
		}
	}

}
